﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using BookManagementWpfApplication.Models;
using System.Windows.Data;

namespace BookManagementWpfApplication.ViewModels
{
    public class BorrowBookViewModel : INotifyPropertyChanged
    {
        private QSHCEntities _qshcEntities;
        public QSHCEntities QSHCEntities
        {
            get { return _qshcEntities; }
            set
            {
                if (_qshcEntities != value)
                {
                    _qshcEntities = value;
                    OnPropertyChanged("QSHCEntities");
                }
            }
        }

        private ICollectionView _bookICV;
        public ICollectionView BookICV
        {
            get { return _bookICV; }
            set
            {
                if (_bookICV != value)
                {
                    _bookICV = value;
                    OnPropertyChanged("BookICV");
                }
            }
        }

        private ICollectionView _borrowICV;
        public ICollectionView BorrowICV
        {
            get { return _borrowICV; }
            set
            {
                if (_borrowICV != value)
                {
                    _borrowICV = value;
                    OnPropertyChanged("BorrowICV");
                }
            }
        }

        public BorrowBookViewModel()
        {
            if (!DesignerProperties.GetIsInDesignMode(new System.Windows.DependencyObject()))
            {
                QSHCEntities = new Models.QSHCEntities();
                BookICV = CollectionViewSource.GetDefaultView(QSHCEntities.BookDatas);
                BorrowICV = CollectionViewSource.GetDefaultView(QSHCEntities.BorrowDatas);
            }
        }

        private void OnPropertyChanged(string caller)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(caller));
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
    }
}
